#ifndef REGISTERPUBLISHER_H
#define REGISTERPUBLISHER_H

#include <string>
#include "header.h"
#include "utils/file.h"

std::string registerPublisherROSOut()
{
    string xml_data = readFile("./registerPublisher.xml");

    CURL *curl;
    CURLcode res;
    string response;
    curl = curl_easy_init();
    if (curl)
    {
        curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
        curl_easy_setopt(curl, CURLOPT_URL, MAS_URI.c_str());
        curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
        curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "http");
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, GetResponse);
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *) &response);
        struct curl_slist *headers = nullptr;
        headers = curl_slist_append(headers, "Content-Type: application/xml");
        curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, xml_data.c_str());
        res = curl_easy_perform(curl);
        if (res != CURLE_OK)
        {
            fprintf(stderr, "registerPublisherROSOut curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
        }
    }
    curl_easy_cleanup(curl);
    return response;
}

#endif //REGISTERPUBLISHER_H
